# coding=utf-8
from pygame import mixer
import time
import json


def PlaySound(word):
    fileJson = json.load(open("./data.json", "rb"))
    playTimes = fileJson["PlayTimes"] # 发音次数
    playDelay = fileJson["PlayDelay"] # 每次发音延时 单位:秒
    i = playTimes
    while i > 0:
        try:
            i = i - 1
            mixer.init()
            a = mixer.Sound("Speech_US/" + word + ".mp3")
            a.play()
            time.sleep(a.get_length())
            a.stop()
            time.sleep(playDelay)
        except Exception as e:
            pass
